package com.sen.design.pattern.creational.simplefactory;

public class VideoFactory {

    public Video getVideo(String type){
        if ("java".equalsIgnoreCase(type)){
            return new JavaVideo();
        }else if ("python".equalsIgnoreCase(type)){
            return new PythonVideo();
        }else{
            return null;
        }
    }

    /**
     * 通过反射扩展，符合开闭原则
     * @param c
     * @return
     */
    public static Video getVideo(Class c){
        Video video = null;
        try {
            video = (Video) Class.forName(c.getName()).newInstance();
        }catch (ClassCastException e1) {
            System.out.println("传入错误的类");
        }catch (InstantiationException | IllegalAccessException | ClassNotFoundException e ) {
            e.printStackTrace();
        }
        return video;
    }
}
